<template>
  <div class="reception-bed">
    <div class="header">
      <h2>床位管理</h2>
      <el-button type="primary" @click="refreshData">刷新</el-button>
    </div>

    <div class="content">
      <!-- 床位统计 -->
      <div class="stats">
        <el-row :gutter="20">
        <el-table-column prop="bedNumber" label="床位号" width="120"></el-table-column>
        <el-table-column prop="status" label="状态" width="100">
          <template #default="scope">
            <el-tag :type="scope.row.status === '空闲' ? 'success' : 'danger'">
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="elderName" label="入住老人"></el-table-column>
        <el-table-column prop="checkinDate" label="入住日期" width="120"></el-table-column>
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'

const bedList = ref([
  {
    roomNumber: '101',
    bedNumber: 'A',
    status: '已入住',
    elderName: '张三',
    checkinDate: '2024-01-15'
  },
  {
    roomNumber: '101',
    bedNumber: 'B',
    status: '空闲',
    elderName: '',
    checkinDate: ''
  },
  {
    roomNumber: '102',
    bedNumber: 'A',
    status: '已入住',
    elderName: '李四',
    checkinDate: '2024-02-20'
  }
])

onMounted(() => {
  // 加载床位数据
  loadBedData()
})

const loadBedData = () => {
  // 这里应该调用API获取床位数据
  console.log('加载床位数据')
}

const handleEdit = (row) => {
  ElMessage.info(`编辑床位: ${row.roomNumber}-${row.bedNumber}`)
}

const handleDelete = (row) => {
  ElMessageBox.confirm(
    `确定要删除床位 ${row.roomNumber}-${row.bedNumber} 吗？`,
    '确认删除',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(() => {
    ElMessage.success('删除成功')
  }).catch(() => {
    ElMessage.info('取消删除')
  })
}
</script>

<style scoped>
.reception-bed {
  padding: 20px;
}

h2 {
  margin-bottom: 20px;
  color: #333;
}
</style>
